package jetbrains.lb.refik;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.xml.*;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;




class RefikReferenceProvider extends PsiReferenceProvider
{

    @NotNull
    @Override
    public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context)
    {
        if (element instanceof XmlTag)
        {
            XmlTag tag = (XmlTag) element;
            PsiFile file = element.getContainingFile();
            Project project = element.getProject();
            RefikProjectComponent rpc =
                    project.getComponent(RefikProjectComponent.class);
            if (rpc == null)
                return noRefs;
            if (!rpc.isFileInvolved(file))
                return noRefs;

            return new PsiReference[] { new RefikPsiReference(tag) };
        }

        return noRefs;
    }


    private static final PsiReference[] noRefs = new PsiReference[0];

}
